﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace mfe_proj.Controls
{
    public partial class YearMonthDay : UserControl
    {
        public YearMonthDay()
        {
            InitializeComponent();
            LoadData();
        }

        private void YearMonthDay_Load(object sender, EventArgs e)
        {
        }

        private void LoadData()
        {
            for (int i = 1; i <= 12; i++)
                cbMonth.Items.Add(i.ToString());
            for (int i = 1; i <= 31; i++)
                cbDay.Items.Add(i.ToString());
            cbMonth.Items.Insert(0, string.Empty);
            cbDay.Items.Insert(0, string.Empty);
        }

        public int? Year
        {
            get
            {
                if (txtYear.Text.Trim().Length == 0)
                    return null;
                else
                    return int.Parse(txtYear.Text.Trim());
            }
            set
            {
                if (value.HasValue)
                    txtYear.Text = value.Value.ToString();
            }
        }

        public int? Month
        {
            get
            {
                if (cbMonth.SelectedIndex == 0)
                    return null;
                else
                    return cbMonth.SelectedIndex;
            }
            set
            {
                if (value.HasValue)
                    cbMonth.SelectedIndex = value.Value;
            }
        }

        public int? Day
        {
            get
            {
                if (cbDay.SelectedIndex == 0)
                    return null;
                else
                    return cbDay.SelectedIndex;
            }
            set
            {
                if (value.HasValue)
                    cbDay.SelectedIndex = value.Value;
            }
        }
    }
}
